/*
 * Created by JFormDesigner on Sun Jun 06 19:54:18 CST 2021
 */

package com.J1ay.carsys.gui.Emp;

import java.awt.event.*;
import com.J1ay.carsys.dto.LoginOutput;
import com.J1ay.carsys.gui.Welcome;

import java.awt.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author Brainrain
 */
public class Main extends JFrame {
    int EmpId;
    String Name;
    public Main(LoginOutput loginOutput) {
        initComponents();
        this.empId.setText("工号："+loginOutput.getEmpId());
        this.empName.setText(loginOutput.getEname()+",欢迎您!");
        EmpId = loginOutput.getEmpId();
        Name = loginOutput.getEname();
    }
    public Main(int id,String name){
        initComponents();
        this.empId.setText("工号："+id);
        this.empName.setText(name+",欢迎您!");
        EmpId = id;
        Name = name;
    }
    public void start() {
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    private void exitActionPerformed(ActionEvent e) {
        // TODO add your code here
        // TODO add your code here
        new Welcome().start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void manageActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Manage(this.EmpId,this.Name).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void carActionPerformed(ActionEvent e) {
        // TODO add your code here
        new CarManage(this.EmpId,this.Name).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Check(this.EmpId,this.Name).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        empName = new JLabel();
        exit = new JButton();
        empId = new JLabel();
        manage = new JButton();
        car = new JButton();
        button1 = new JButton();

        //======== this ========
        setTitle("\u5c0f\u6c7d\u8f66\u51fa\u79df\u7cfb\u7edf");
        Container contentPane = getContentPane();

        //---- empName ----
        empName.setText("\u6b22\u8fce\u60a8!");

        //---- exit ----
        exit.setText("\u9000\u51fa");
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exitActionPerformed(e);
            }
        });

        //---- empId ----
        empId.setText("\u5de5\u53f7\uff1a");

        //---- manage ----
        manage.setText("\u4eba\u5458\u7ba1\u7406");
        manage.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                manageActionPerformed(e);
            }
        });

        //---- car ----
        car.setText("\u8f66\u8f86\u7ba1\u7406");
        car.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                carActionPerformed(e);
            }
        });

        //---- button1 ----
        button1.setText("\u5ba1\u6838\u7ba1\u7406");
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button1ActionPerformed(e);
            }
        });

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addGap(50, 50, 50)
                    .addComponent(manage, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
                    .addGap(28, 28, 28)
                    .addComponent(car, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 79, Short.MAX_VALUE))
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap(146, Short.MAX_VALUE)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                            .addComponent(empName, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                            .addGap(137, 137, 137))
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                            .addComponent(exit)
                            .addGap(29, 29, 29))))
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(empId, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(130, 130, 130)
                            .addComponent(button1)))
                    .addContainerGap(159, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(10, 10, 10)
                    .addComponent(empId, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
                    .addGap(11, 11, 11)
                    .addComponent(empName, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(manage)
                        .addComponent(car))
                    .addGap(18, 18, 18)
                    .addComponent(button1)
                    .addGap(23, 23, 23)
                    .addComponent(exit)
                    .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel empName;
    private JButton exit;
    private JLabel empId;
    private JButton manage;
    private JButton car;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
